﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Text.RegularExpressions;

namespace homework6
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Submit_Click(object sender, EventArgs e)
        {
            if (URL.Text.Length == 0)
                return;
            if (result.Text.Length != 0)
                result.ResetText();
            string url = @URL.Text;
            WebClient wc = new WebClient();
            byte[] input=wc.DownloadData(url);
            string page=Encoding.UTF8.GetString(input);
            //URL.Text = "";
            string pattern = @"\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}|1[0-9]{10}$|[0-9]{3,4}-[0-9]{7,8}";
            MatchCollection mc = Regex.Matches(page, pattern);
            foreach (Match m in mc)
            {
                result.AppendText(m.ToString());
                result.AppendText(System.Environment.NewLine);
            }
        }
    }
}
